home *** CD-ROM | disk | FTP | other *** search
/ Aminet 1 (Walnut Creek) / Aminet - June 1993 [Walnut Creek].iso / usenet / sources / volume2 / libraris / gimme.4 < prev    next >
Text File  |  1988-12-02  |  58KB  |  2,287 lines

  1. Path: xanth!nic.MR.NET!hal!cwjcc!tut.cis.ohio-state.edu!bloom-beacon!mit-eddie!ll-xn!adelie!infinet!ulowell!page
  2. From: page@swan.ulowell.edu (Bob Page)
  3. Newsgroups: comp.sources.amiga
  4. Subject: v02i077:  gimme.lib - misc library routines, Part04/07
  5. Message-ID: <10415@swan.ulowell.edu>
  6. Date: 2 Dec 88 01:01:42 GMT
  7. Organization: University of Lowell, Computer Science Dept.
  8. Lines: 2276
  9. Approved: page@swan.ulowell.edu
  10.  
  11. Submitted-by: oscvax!jan@uunet.UU.NET (Jan Sven Trabandt)
  12. Posting-number: Volume 2, Issue 77
  13. Archive-name: libraries/gimme.4
  14.  
  15. #    This is a shell archive.
  16. #    Remove everything above and including the cut line.
  17. #    Then run the rest of the file through sh.
  18. #----cut here-----cut here-----cut here-----cut here----#
  19. #!/bin/sh
  20. # shar:    Shell Archiver
  21. #    Run the following text with /bin/sh to create:
  22. #    bitmap.c
  23. #    bitplane.c
  24. #    color.c
  25. #    communic.c
  26. #    copystuff.c
  27. #    dbuf.c
  28. #    dbufquick.c
  29. #    dbufvquick.c
  30. #    dualpf.c
  31. #    font.c
  32. #    gadget.c
  33. #    gadgstuff.c
  34. # This archive created: Thu Dec  1 19:50:54 1988
  35. cat << \SHAR_EOF > bitmap.c
  36. /*
  37.  *  FILE: bitmap.c
  38.  *  Support routines for dynamic (de)allocation of bitmaps.
  39.  *
  40.  *  Public Domain, but keep my name in it as the original author.
  41.  *  31-Aug-88    Jan Sven Trabandt   first release version
  42.  */
  43.  
  44.  
  45. #include "gimmelib/gimmefuncs.h"
  46.  
  47.  
  48. struct BitMap *gimmeBitMap( depth, width, height )
  49.     SHORT   depth, width, height;
  50. {
  51.     register struct BitMap  *bm;
  52.     SHORT            i;
  53.  
  54.     bm = (struct BitMap *) AllocMem( (ULONG)sizeof(struct BitMap),
  55.                     MEMF_PUBLIC | MEMF_CLEAR );
  56.     if( !bm ) {
  57.     return( NULL );
  58.     }
  59.     if( depth > 0 && width > 0 && height > 0 ) {
  60.     InitBitMap( bm, (ULONG) depth, (ULONG) width, (ULONG) height );
  61.     for( i = 0; i < depth; ++i ) {
  62.         if( !(bm->Planes[i] = (PLANEPTR)
  63.                     AllocRaster((ULONG)width,(ULONG)height)) ) {
  64.         bm->Depth = i;
  65.         getRidOfBitMap( bm );
  66.         return( NULL );
  67.         }
  68.         BltClear( bm->Planes[i],
  69.             (ULONG)RASSIZE((ULONG)width,(ULONG)height), 0L );
  70.     } /* for */
  71.     }
  72.     return( bm );
  73. } /* gimmeBitMap */
  74.  
  75.  
  76. short getRidOfBitMap( bitmap )
  77.     register struct BitMap  *bitmap;
  78. {
  79.     SHORT   i;
  80.     SHORT   width;
  81.  
  82. #ifdef GIMME_WIMPY
  83.     if( !bitmap ) {
  84.     return( -1 );
  85.     }
  86. #endif
  87.     width = bitmap->BytesPerRow << 3;
  88.     for( i = 0; i < bitmap->Depth && bitmap->Planes[i]; ++i ) {
  89.     FreeRaster( bitmap->Planes[i], (ULONG) width, (ULONG) bitmap->Rows );
  90.     } /* for */
  91.     FreeMem( bitmap, (ULONG)sizeof(struct BitMap) );
  92.     return( 0 );
  93. } /* getRidOfBitMap */
  94. SHAR_EOF
  95. cat << \SHAR_EOF > bitplane.c
  96. /*
  97.  *  FILE: bitplane.c
  98.  *  Support routines for dynamic (de)allocation of bitplanes for bitmaps
  99.  *  and/or image data.
  100.  *
  101.  *  Public Domain, but keep my name in it as the original author.
  102.  *  31-Aug-88    Jan Sven Trabandt   first release version
  103.  */
  104.  
  105.  
  106. #define I_AM_BITPLANE
  107. #include "gimmelib/gimmefuncs.h"
  108. #include "gimmelib/bitplane.h"
  109.  
  110.  
  111. ULONG gimmeBitPlanes( bm, myflags )
  112.     struct BitMap   *bm;
  113.     ULONG        myflags;
  114. {
  115.     SHORT   i;
  116.     SHORT   width, height, depth;
  117.     ULONG   planesize;
  118.  
  119. #ifdef GIMME_WIMPY
  120.     if( !bm ) {
  121.     return( GBP_ERROR );
  122.     }
  123. #endif
  124.     width = bm->BytesPerRow << 3;
  125.     height = bm->Rows;
  126.     depth = bm->Depth;
  127.     planesize = RASSIZE((ULONG)width, (ULONG)height);
  128.     bm->Planes[0] = NULL;
  129.     if( myflags & GBP_CONTIGUOUS ) {
  130.     if( bm->Planes[0] = AllocMem( (ULONG)(depth) * planesize,
  131.                     MEMF_CHIP | MEMF_CLEAR) ) {
  132.         for( i = 1; i < depth; ++i ) {
  133.         bm->Planes[i] = (UBYTE *)(bm->Planes[i-1]) + planesize;
  134.         } /* for */
  135.         return( GBP_CONTIGUOUS );
  136.     }
  137.     }
  138.     if( (myflags & GBP_SEPARATE) || !myflags ) {
  139.     for( i = 0; i < depth; ++i ) {
  140.         if( !(bm->Planes[i] = (PLANEPTR)
  141.                     AllocRaster((ULONG)width,(ULONG)height)) ) {
  142.         while( --i >= 0 ) {
  143.             FreeRaster( bm->Planes[i], (ULONG) bm->BytesPerRow << 3,
  144.                     (ULONG) bm->Rows );
  145.         } /* while */
  146.         return( GBP_ERROR );
  147.         }
  148.         BltClear( bm->Planes[i], planesize, 0L );
  149.     } /* for */
  150.     return( GBP_SEPARATE );
  151.     }
  152.     return( GBP_ERROR );
  153. } /* gimmeBitPlanes */
  154.  
  155.  
  156. short getRidOfBitPlanes( bm, myflags )
  157.     struct BitMap   *bm;
  158.     ULONG        myflags;
  159. {
  160.     SHORT   i;
  161.     SHORT   width, height, depth;
  162.  
  163. #ifdef GIMME_WIMPY
  164.     if( !bm ) {
  165.     return( -1 );
  166.     }
  167. #endif
  168.     width = bm->BytesPerRow << 3;
  169.     height = bm->Rows;
  170.     depth = bm->Depth;
  171.     if( myflags & GBP_CONTIGUOUS ) {
  172.     FreeMem( bm->Planes[0],
  173.             (ULONG)(depth) * RASSIZE((ULONG)width,(ULONG)height) );
  174.     } else {
  175.     for( i = 0; i < depth && bm->Planes[i]; ++i ) {
  176.         FreeRaster( bm->Planes[i], (ULONG) width, (ULONG) height );
  177.     } /* for */
  178.     }
  179.     return( 0 );
  180. } /* getRidOfBitPlanes */
  181. SHAR_EOF
  182. cat << \SHAR_EOF > color.c
  183. /*
  184.  *  FILE: color.c
  185.  *  Support routines for dealing with the color of an Intuition screen.
  186.  *
  187.  *  Public Domain, but keep my name in it as the original author.
  188.  *  31-Aug-88    Jan Sven Trabandt   first release version
  189.  */
  190.  
  191.  
  192. #define I_AM_COLOR
  193. #include <clib/macros.h>
  194. #include "gimmelib/gimmefuncs.h"
  195. #include "gimmelib/color.h"
  196.  
  197.  
  198. USHORT *getDefaultColors()
  199. {
  200.     if( DFLT_MAX_COLORS > 0 ) {
  201.     return( gimColorTable );
  202.     } else {
  203.     return( NULL );
  204.     }
  205. } /* getDefaultColors */
  206.  
  207.  
  208. short setColors( screen, ctable, colors )
  209.     struct Screen   *screen;
  210.     USHORT        *ctable;
  211.     SHORT        colors;
  212. {
  213. #ifdef GIMME_WIMPY
  214.     if( !screen || colors <= 0 ) {
  215.     return( -1 );
  216.     }
  217. #endif
  218.     if( ctable ) {
  219.     colors = MIN( colors, screen->ViewPort.ColorMap->Count );
  220.     } else {
  221.     if( colors > DFLT_MAX_COLORS ) {
  222.         return( -1 );
  223.     }
  224.     ctable = gimColorTable;
  225.     }
  226.     LoadRGB4( &screen->ViewPort, ctable, (ULONG) colors );
  227.     return( 0 );
  228. } /* setColors */
  229.  
  230.  
  231. #define TEST_TEXT    "hi!"
  232. #define TEST_TEXT_LEN    3    /* strlen(TEST_TEXT) */
  233.  
  234. short checkColors( screen, colors )
  235.     struct Screen   *screen;
  236.     SHORT        colors;
  237. {
  238.     register struct RastPort    *rp;
  239.     SHORT   i, j;
  240.     SHORT   x, y;
  241.  
  242. #ifdef GIMME_WIMPY
  243.     if( !screen ) {
  244.     return( -1 );
  245.     }
  246. #endif
  247.     rp = &screen->RastPort;
  248.     colors = MIN( colors, screen->ViewPort.ColorMap->Count );
  249.     x = 0;
  250.     y = screen->BarHeight + rp->TxHeight;
  251.     j = 0;
  252.     for( i = 0; i < colors; ++i ) {
  253.     SetAPen( rp, (ULONG) i );
  254.     if( !(i % 4) ) {
  255.         y += rp->TxHeight;
  256.         x = 0;
  257.     } else {
  258.         x += (TEST_TEXT_LEN+1) * rp->TxWidth;
  259.     }
  260.     Move( rp, (ULONG) x, (ULONG) y );
  261.     Text( rp, TEST_TEXT, (ULONG) TEST_TEXT_LEN );
  262.     }
  263.     return( 0 );
  264. } /* checkColors */
  265. SHAR_EOF
  266. cat << \SHAR_EOF > communic.c
  267. /*
  268.  *  FILE: communic.c
  269.  *  Support routines for accessing, reading and writing to the serial port.
  270.  *
  271.  *  NOTE: these routines provide EXCLUSIVE access to the serial port for one
  272.  *  task only.    This shouldn't be too great a problem given the nature of the
  273.  *  serial port.
  274.  *
  275.  *  Public Domain, but keep our names in it as the original authors.
  276.  *  11-May-87    Scotte Zinn        created
  277.  *  15-Mar-88    Jan Sven Trabandt   changed c_set_error to a macro
  278.  *                    made sure it works with short (16 bit) ints
  279.  *  27-Apr-88    Jan Sven Trabandt   lots of goodies
  280.  *  31-Oct-88    Jan Sven Trabandt   added to gimme.lib (finally)
  281.  */
  282.  
  283.  
  284. #define I_AM_COMMUNIC
  285. #include "gimmelib/gimmefuncs.h"
  286. #include "gimmelib/communic.h"
  287. #include <devices/serial.h>
  288.  
  289.  
  290. #define C_NOT_OPEN    0
  291. #define BUFFER_LENGTH    4096
  292. #define INIT_VALUE    29451
  293.  
  294. #define initialized()       ((SHORT)initial != 0)
  295. #define channel_open()      ((SHORT)system_state != C_NOT_OPEN)
  296. #define c_set_error(err)    (c_error = err)
  297.  
  298. static struct IOExtSer    *IORser = NULL;
  299. static struct MsgPort    *SPort = NULL;
  300. static struct timerequest *treq = NULL;
  301. static char EOLchar = DEFAULT_EOL;
  302. static SHORT system_state = C_NOT_OPEN;
  303. static SHORT initial = 0;
  304.  
  305. short c_error;
  306.  
  307. /* forward declarations */
  308. static short c_getchar();
  309.  
  310.  
  311. short c_init()
  312. {
  313.     if( !initialized() ) {
  314.     /* Set system state to channel not open and set initialized flag */
  315.     Forbid();
  316.     initial = INIT_VALUE;
  317.     system_state = C_NOT_OPEN;
  318.     Permit();
  319.     }
  320.     return( c_set_error(C_ERR_OK) );
  321. } /* c_init */
  322.  
  323.  
  324. short c_open( parms )
  325.     struct c_parameters *parms;
  326. {
  327.     short   error;
  328.  
  329.     if( !parms ) {
  330.     return( c_set_error(C_ERR_BADPARM) );
  331.     }
  332.     if( !initialized() )
  333.     return( c_set_error(C_ERR_INITIAL) );
  334.     if( channel_open() )
  335.     return( c_set_error(C_ERR_OPEN) );
  336.  
  337.     /* Now access timer device for future time-outs and to get a Port */
  338.     if( !(treq = accessTimer(UNIT_VBLANK, &SPort)) ) {
  339.     return( c_set_error(C_ERR_CANT) );
  340.     }
  341.  
  342.     IORser = (struct IOExtSer *) CreateExtIO( SPort,
  343.                     (ULONG)sizeof(struct IOExtSer) );
  344.     if( !IORser ) {
  345.     releaseTimer( treq, NULL );
  346.     return( c_set_error(C_ERR_CANT) );
  347.     }
  348.  
  349.     if( parms->C_MODE == C_SER_7 ) {
  350.     IORser->io_SerFlags = SERB_7WIRE | SERB_XDISABLED;
  351.     }
  352.     if( OpenDevice(SERIALNAME, 0L, IORser, 0L) ) {
  353.     DeleteExtIO( IORser, (ULONG)sizeof(struct IOExtSer) );
  354.     releaseTimer( treq, NULL );
  355.     return( c_set_error(C_ERR_CANT) );
  356.     }
  357.  
  358.     system_state = -1;            /* Now set channel opened */
  359.  
  360.     if( error = c_setup(parms) ) {
  361.     CloseDevice( IORser );
  362.     DeleteExtIO( IORser, (ULONG)sizeof(struct IOExtSer) );
  363.     releaseTimer( treq, NULL );
  364.     system_state = C_NOT_OPEN;
  365.     return( c_set_error(error) );
  366.     }
  367.     EOLchar = DEFAULT_EOL;
  368.  
  369.     /* Channel is now successfully opened */
  370.     return( c_set_error(C_ERR_OK) );
  371. } /* c_open */
  372.  
  373.  
  374. short c_setup( parms )
  375.     struct c_parameters *parms;
  376. {
  377.     if( !(initialized() && channel_open()) )    /* important to check here */
  378.     return( c_set_error(C_ERR_CHAN) );
  379.     if( !parms ) {
  380.     return( c_set_error(C_ERR_BADPARM) );
  381.     }
  382.  
  383.     /* Now set parameters as requested */
  384.     IORser->io_ReadLen    = parms->C_RLEN;
  385.     IORser->io_BrkTime    = 750000L;
  386.     IORser->io_Baud    = parms->C_BAUD;
  387.     IORser->io_WriteLen = parms->C_WLEN;
  388.     IORser->io_StopBits = parms->C_STOP;
  389.     IORser->io_RBufLen     = BUFFER_LENGTH;
  390.  
  391.     /* Setup parity bits with validation */
  392.     IORser->io_SerFlags &= ~(SERB_PARTY_ODD & SERB_PARTY_ON);
  393.  
  394.     switch( parms->C_PARITY ) {
  395.       case C_NO_PARITY:
  396.     break;
  397.       case C_ODD_PARITY:
  398.     IORser->io_SerFlags |= SERB_PARTY_ODD | SERB_PARTY_ON;
  399.     break;
  400.       case C_EVEN_PARITY:
  401.     IORser->io_SerFlags |= SERB_PARTY_ON;
  402.     break;
  403.       default:
  404.     return( c_set_error(C_ERR_PARITY) );
  405.     } /* switch */
  406.  
  407.     IORser->IOSer.io_Command = SDCMD_SETPARAMS;
  408.     IORser->io_TermArray.TermArray0 = 0x51040303;
  409.     IORser->io_TermArray.TermArray1 = 0x03030303;
  410.  
  411.     if( DoIO(IORser) )
  412.     return( c_set_error(C_ERR_PARAMS) );
  413.  
  414.     /* Parameters were changed as needed */
  415.     return( c_set_error(C_ERR_OK) );
  416. } /* c_setup */
  417.  
  418.  
  419. /* internal use only!
  420. static short c_getchar( cinput, secs, micros )
  421.     char    *cinput;
  422.     ULONG   secs, micros;
  423. {
  424.     APTR    myptr;
  425.     short   iodone = 0;
  426.  
  427.     /* Send request for read a character */
  428.     IORser->IOSer.io_Data = (APTR) cinput;
  429.     IORser->IOSer.io_Length = 1;
  430.     IORser->IOSer.io_Command = CMD_READ;
  431.     SendIO( IORser );
  432.  
  433.     if( CheckIO(IORser) ) {
  434.     Remove( IORser );
  435.     return( c_set_error(C_ERR_OK) );
  436.     } else {
  437.     timeDelayAsync( secs, micros, UNIT_VBLANK, treq );
  438.     WaitPort( SPort );
  439.     while( myptr = (APTR) GetMsg(SPort) ) {
  440.         if( myptr == (APTR) IORser ) {
  441.         iodone = -1;
  442.         }
  443.     } /* while */
  444.     if( iodone ) {
  445.         killTimeDelay( treq );
  446.         return( c_set_error(C_ERR_OK) );
  447.     }
  448.     }
  449.  
  450.     /* Abort the requested IO and return error condition */
  451.     AbortIO( IORser );
  452.     Remove( IORser );
  453.     return( c_set_error(C_ERR_GET) );
  454. } /* c_getchar */
  455.  
  456.  
  457. short c_getc( cinput )
  458.     char    *cinput;
  459. {
  460. #ifdef GIMME_WIMPY
  461.     if( !(initialized() && channel_open()) )
  462.     return( c_set_error(C_ERR_CHAN) );
  463.     if( !buffer ) {
  464.     return( c_set_error(C_ERR_BADPARM) );
  465.     }
  466. #endif
  467.     return( c_getchar(cinput, BIG_SECS, BIG_MICROS) );
  468. } /* c_getc */
  469.  
  470.  
  471. short c_emptyc()
  472. {
  473.     short   err;
  474.     char    cinput;
  475.  
  476. #ifdef GIMME_WIMPY
  477.     if( !(initialized() && channel_open()) )
  478.     return( c_set_error(C_ERR_CHAN) );
  479. #endif
  480.     /* Empty the buffer */
  481.     while( (err = c_getchar(&cinput, SMALL_SECS, SMALL_MICROS)) == C_ERR_OK ) {
  482.     } /* while */
  483.  
  484.     /* Check for a buffer empty error and replace with ok status */
  485.     if( err == C_ERR_GET ) {
  486.     c_set_error(err = C_ERR_OK);
  487.     }
  488.     /* Return status of empty */
  489.     return( err );
  490. } /* c_emptyc */
  491.  
  492.  
  493. short c_putc( coutput )
  494.     char coutput;
  495. {
  496. #ifdef GIMME_WIMPY
  497.     if( !(initialized() && channel_open()) )
  498.     return( c_set_error(C_ERR_CHAN) );
  499. #endif
  500.     /* Now send character thru channel */
  501.     IORser->IOSer.io_Data = (APTR) &coutput;
  502.     IORser->IOSer.io_Length = 1;
  503.     IORser->IOSer.io_Command = CMD_WRITE;
  504.     if( DoIO(IORser) ) {
  505.     return( c_set_error(C_ERR_PUT) );
  506.     }
  507.     return( c_set_error(C_ERR_OK) );
  508. } /* c_putc */
  509.  
  510.  
  511. short c_gets( buffer, num_to_get )
  512.     char    *buffer;
  513.     SHORT   num_to_get;
  514. {
  515.     register SHORT  i;
  516.     short        error;
  517.  
  518. #ifdef GIMME_WIMPY
  519.     if( !(initialized() && channel_open()) )
  520.     return( c_set_error(C_ERR_CHAN) );
  521.     if( !buffer ) {
  522.     return( c_set_error(C_ERR_BADPARM) );
  523.     }
  524. #endif
  525.     if( num_to_get <= 0 ) {
  526.     return( c_set_error(C_ERR_ILLEGAL) );
  527.     }
  528.  
  529.     /* Now get the specified number of characters */
  530.     for( i = num_to_get; --i >= 0; ++buffer ) {
  531.     if( error = c_getchar(buffer, BIG_SECS, BIG_MICROS) ) {
  532.         return( c_set_error(error) );
  533.     }
  534.     } /* for */
  535.  
  536.     return( c_set_error(C_ERR_OK) );
  537. } /* c_gets */
  538.  
  539.  
  540. short c_getline( buffer, num_to_get )
  541.     char    *buffer;
  542.     SHORT   num_to_get;
  543. {
  544.     register SHORT  i;
  545.     short        error;
  546.  
  547. #ifdef GIMME_WIMPY
  548.     if( !(initialized() && channel_open()) )
  549.     return( c_set_error(C_ERR_CHAN) );
  550.     if( !buffer ) {
  551.     return( c_set_error(C_ERR_BADPARM) );
  552.     }
  553. #endif
  554.     if( num_to_get <= 0 ) {
  555.     return( c_set_error(C_ERR_ILLEGAL) );
  556.     }
  557.  
  558.     /* Now get the specified number of characters */
  559.     for( i = num_to_get; --i >= 0; ++buffer ) {
  560.     if( error = c_getchar(buffer, SMALL_SECS, SMALL_MICROS) ) {
  561.         *buffer = '\0';
  562.         return( c_set_error(error) );
  563.     }
  564.     if( *buffer == EOLchar ) {
  565.         break;
  566.     }
  567.     } /* for */
  568.  
  569.     return( c_set_error(C_ERR_OK) );
  570. } /* c_getline */
  571.  
  572.  
  573. short c_setEOL( character )
  574.     char character;
  575. {
  576. #ifdef GIMME_WIMPY
  577.     if( !(initialized() && channel_open()) )
  578.     return( c_set_error(C_ERR_CHAN) );
  579. #endif
  580.     EOLchar = character;
  581.     return( c_set_error(C_ERR_OK) );
  582. } /* c_setEOL */
  583.  
  584.  
  585. short c_puts( buffer, num_to_put )
  586.     char    *buffer;
  587.     SHORT   num_to_put;
  588. {
  589.     short   error;
  590.  
  591. #ifdef GIMME_WIMPY
  592.     if( !(initialized() && channel_open()) )
  593.     return( c_set_error(C_ERR_CHAN) );
  594.     if( !buffer ) {
  595.     return( c_set_error(C_ERR_BADPARM) );
  596.     }
  597. #endif
  598.     if( num_to_put <= 0 ) {
  599.     return( c_set_error(C_ERR_ILLEGAL) );
  600.     }
  601.     /* Now send the characters thru channel */
  602.     IORser->IOSer.io_Data = (APTR) buffer;
  603.     IORser->IOSer.io_Length = num_to_put;
  604.     IORser->IOSer.io_Command = CMD_WRITE;
  605.     if( DoIO(IORser) ) {
  606.     return( c_set_error(C_ERR_PUT) );
  607.     }
  608.     return( c_set_error(C_ERR_OK) );
  609. } /* c_puts */
  610.  
  611.  
  612. short c_close()
  613. {
  614.     short   err;
  615.  
  616. #ifdef GIMME_WIMPY
  617.     if( !(initialized() && channel_open()) )
  618.     return( c_set_error(C_ERR_CHAN) );
  619. #endif
  620.  
  621.     if( err = c_emptyc() ) {            /* Empty the buffer */
  622.     return( err );
  623.     }
  624.     /* Now close device and channel */
  625.     CloseDevice( IORser );
  626.     DeleteExtIO( IORser, (ULONG)sizeof(struct IOExtSer) );
  627.     releaseTimer( treq, NULL );         /* Now close timer device */
  628.     SPort = NULL;
  629.     system_state = C_NOT_OPEN;
  630.     return( c_set_error(C_ERR_OK) );
  631. } /* c_close */
  632.  
  633.  
  634. short c_done()
  635. {
  636.     if( initialized() ) {
  637.     /* Set system state to channel not open and clear initialized flag */
  638.     Forbid();
  639.     initial = 0;
  640.     system_state = C_NOT_OPEN;
  641.     Permit();
  642.     }
  643.     return( c_set_error(C_ERR_OK) );
  644. } /* c_done */
  645. SHAR_EOF
  646. cat << \SHAR_EOF > copystuff.c
  647. /*
  648.  *  FILE: copystuff.c
  649.  *  Support routines for copying (mainly intuition-type) structures.
  650.  *
  651.  *  Public Domain, but keep my name in it as the original author.
  652.  *  31-Oct-88    Jan Sven Trabandt   split from intuistuff.c
  653.  *                    added more functions
  654.  */
  655.  
  656.  
  657. #define I_AM_COPYSTUFF
  658. #include "gimmelib/gimmefuncs.h"
  659. #include "gimmelib/copystuff.h"
  660. #include "gimmelib/intuistuff.h"
  661. #define GIM_BUILTIN
  662. #include "gimmelib/macros.h"
  663.  
  664.  
  665. short copyDataImage( data, image )
  666.     USHORT  *data;
  667.     register struct Image   *image;
  668. {
  669.     register struct Image   *ip;
  670.     ULONG   size;            /* image datasize (bytes) for copying */
  671.     UBYTE   *idata, *srcdata;        /* UBYTE makes additions easier */
  672.  
  673. #ifdef GIMME_WIMPY
  674.     if( !data || !image || !image->ImageData ) {
  675.     return( -1 );
  676.     }
  677. #endif
  678.     size = GIM_IMAGESIZE(image->Depth, image->Width, image->Height);
  679.     if( size > 0x07fffL ) {
  680.     idata = (UBYTE *) image->ImageData;
  681.     srcdata = (UBYTE *) data;
  682.     for( ; size > 0L; size -= 0x07fffL ) {
  683.         movmem( srcdata, idata, (int)(size & 0x07fffL) );
  684.         srcdata += 0x07fffL;
  685.         idata += 0x07fffL;
  686.     } /* for */
  687.     } else {
  688.     movmem( data, image->ImageData, (int) size );
  689.     }
  690.     return( 0 );
  691. } /* copyDataImage */
  692.  
  693.  
  694. short copyImageData( image, data )
  695.     register struct Image   *image;
  696.     USHORT  *data;
  697. {
  698.     register struct Image   *ip;
  699.     ULONG   size;            /* image datasize (bytes) for copying */
  700.     UBYTE   *idata, *destdata;        /* UBYTE makes additions easier */
  701.  
  702. #ifdef GIMME_WIMPY
  703.     if( !data || !image || !image->ImageData ) {
  704.     return( -1 );
  705.     }
  706. #endif
  707.     size = GIM_IMAGESIZE(image->Depth, image->Width, image->Height);
  708.     if( size > 0x07fffL ) {
  709.     idata = (UBYTE *) image->ImageData;
  710.     destdata = (UBYTE *) data;
  711.     for( ; size > 0L; size -= 0x07fffL ) {
  712.         movmem( idata, destdata, (int)(size & 0x07fffL) );
  713.         idata += 0x07fffL;
  714.         destdata += 0x07fffL;
  715.     } /* for */
  716.     } else {
  717.     movmem( image->ImageData, data, (int) size );
  718.     }
  719.     return( 0 );
  720. } /* copyImageData */
  721.  
  722.  
  723. struct Border *copyBorder( mh, oldbp, numbord, myflags )
  724.     void    **mh;
  725.     register struct Border  *oldbp;
  726.     SHORT   numbord;
  727.     ULONG   myflags;
  728. {
  729.     register struct Border  *bp;
  730.     struct Border        *retbp, *temp;
  731.     ULONG            size;
  732.     void            *mymh = NULL;
  733.  
  734. #ifdef GIMME_WIMPY
  735.     if( !mh ) {
  736.     return( NULL );
  737.     }
  738. #endif
  739.     retbp = bp = NULL;
  740.     for( ; oldbp && numbord != 0; oldbp = oldbp->NextBorder, --numbord ) {
  741.     if( !(temp = chainAllocMem(&mymh, (ULONG)sizeof(struct Border),
  742.                     MEMF_PUBLIC)) ) {
  743.         if( !(myflags & GCP_SALVAGE) ) {
  744.         chainFreeMem( mymh );
  745.         retbp = NULL;
  746.         }
  747.         return( retbp );
  748.     }
  749.     if( !bp ) {
  750.         retbp = temp;
  751.     } else {
  752.         bp->NextBorder = temp;
  753.     }
  754.     bp = temp;
  755.     *bp = *oldbp;        /* struct copy */
  756.     if( oldbp->XY && !(myflags & GCP_NOT_POINTS) ) {
  757.         size = sizeof(SHORT) * 2L  * bp->Count;
  758.         if( !(bp->XY = chainAllocMem(&mymh, size, MEMF_PUBLIC)) ) {
  759.         if( !(myflags & GCP_SALVAGE) ) {
  760.             chainFreeMem( mymh );
  761.             return( NULL );
  762.         } else {
  763.             bp->Count = 0;
  764.         }
  765.         } else {
  766.         movmem( oldbp->XY, bp->XY, (int)size );
  767.         }
  768.     }
  769.     } /* for */
  770.     linkChainMem( mh, mymh );
  771.     return( retbp );
  772. } /* copyBorder */
  773.  
  774.  
  775. struct Image *copyImage( mh, oldip, numimage, myflags )
  776.     void    **mh;
  777.     register struct Image   *oldip;
  778.     SHORT   numimage;
  779.     ULONG   myflags;
  780. {
  781.     register struct Image   *ip;
  782.     struct Image        *retip, *temp;
  783.     ULONG            size;
  784.     void            *mymh = NULL;
  785.  
  786. #ifdef GIMME_WIMPY
  787.     if( !mh ) {
  788.     return( NULL );
  789.     }
  790. #endif
  791.     retip = ip = NULL;
  792.     for( ; oldip && numimage != 0; oldip = oldip->NextImage, --numimage ) {
  793.     if( !(temp = chainAllocMem(&mymh, (ULONG)sizeof(struct Image),
  794.                     MEMF_PUBLIC)) ) {
  795.         if( !(myflags & GCP_SALVAGE) ) {
  796.         chainFreeMem( mymh );
  797.         retip = NULL;
  798.         }
  799.         return( retip );
  800.     }
  801.     if( !ip ) {
  802.         retip = temp;
  803.     } else {
  804.         ip->NextImage = temp;
  805.     }
  806.     ip = temp;
  807.     *ip = *oldip;        /* struct copy */
  808.     if( oldip->ImageData && !(myflags & GCP_NOT_BYTES) ) {
  809.         size = GIM_IMAGESIZE(ip->Depth, ip->Width, ip->Height);
  810.         if( !(ip->ImageData = chainAllocMem(&mymh, size, MEMF_PUBLIC)) ) {
  811.         if( !(myflags & GCP_SALVAGE) ) {
  812.             chainFreeMem( mymh );
  813.             return( NULL );
  814.         }
  815.         } else {
  816.         copyImageData( oldip, ip->ImageData );
  817.         }
  818.     }
  819.     } /* for */
  820.     linkChainMem( mh, mymh );
  821.     return( retip );
  822. } /* copyImage */
  823.  
  824.  
  825. struct IntuiText *copyIntuiText( mh, otext, numitext, myflags )
  826.     void    **mh;
  827.     register struct IntuiText    *otext;
  828.     SHORT   numitext;
  829.     ULONG   myflags;
  830. {
  831.     register struct IntuiText    *itext;
  832.     struct IntuiText        *retitext, *temp;
  833.     ULONG            size;
  834.     void            *mymh = NULL;
  835.  
  836. #ifdef GIMME_WIMPY
  837.     if( !mh ) {
  838.     return( NULL );
  839.     }
  840. #endif
  841.     retitext = itext = NULL;
  842.     for( ; otext && numitext != 0; otext = otext->NextText, --numitext ) {
  843.     if( !(temp = chainAllocMem(&mymh, (ULONG)sizeof(struct IntuiText),
  844.                     MEMF_PUBLIC)) ) {
  845.         if( !(myflags & GCP_SALVAGE) ) {
  846.         chainFreeMem( mymh );
  847.         retitext = NULL;
  848.         }
  849.         return( retitext );
  850.     }
  851.     if( !itext ) {
  852.         retitext = temp;
  853.     } else {
  854.         itext->NextText = temp;
  855.     }
  856.     itext = temp;
  857.     *itext = *otext;       /* struct copy */
  858.     if( otext->IText && !(myflags & GCP_NOT_STRING) ) {
  859.         size = strlen( otext->IText );
  860.         if( !(itext->IText = chainAllocMem(&mymh, size, MEMF_PUBLIC)) ) {
  861.         if( !(myflags & GCP_SALVAGE) ) {
  862.             chainFreeMem( mymh );
  863.             return( NULL );
  864.         }
  865.         } else {
  866.         /* strcpy( itext->IText, otext->IText ); */
  867.         movmem( otext->IText, itext->IText, (int) size + 1 );
  868.         }
  869.     }
  870.     if( otext->ITextFont && !(myflags & GCP_NOT_TEXTATTR) ) {
  871.         if( !(itext->ITextFont = chainAllocMem(&mymh,
  872.             (ULONG)sizeof(struct TextAttr), MEMF_PUBLIC)) ) {
  873.         if( !(myflags & GCP_SALVAGE) ) {
  874.             chainFreeMem( mymh );
  875.             return( NULL );
  876.         }
  877.         } else {
  878.         *itext->ITextFont = *otext->ITextFont;        /* struct copy */
  879.         }
  880.     }
  881.     } /* for */
  882.     linkChainMem( mh, mymh );
  883.     return( retitext );
  884. } /* copyIntuiText */
  885.  
  886.  
  887. struct MenuItem *copyMenuItem( mhptr, olditem, numitem, numsub, myflags )
  888.     void            **mhptr;
  889.     register struct MenuItem    *olditem;
  890.     SHORT            numitem, numsub;
  891.     ULONG            myflags;
  892. {
  893.     register struct MenuItem    *item, *temp;
  894.     struct MenuItem        *menuitem = NULL;
  895.     APTR            (*copyfunc)();
  896.     void            *mymh = NULL;
  897.  
  898. #ifdef GIMME_WIMPY
  899.     if( !mhptr ) {
  900.     return( NULL );
  901.     }
  902. #endif
  903.     item = NULL;
  904.     for( ; olditem && numitem != 0; olditem = olditem->NextItem ) {
  905.     if( !(temp = chainAllocMem(&mymh, (ULONG)sizeof(struct MenuItem),
  906.                         MEMF_PUBLIC)) ) {
  907.         chainFreeMem( mymh );
  908.         return( NULL );
  909.     }
  910.     if( !item ) {
  911.         menuitem = temp;
  912.     } else {
  913.         item->NextItem = temp;
  914.     }
  915.     item = temp;
  916.     *item = *olditem;    /* struct copy */
  917.     if( !(myflags & GCP_NOT_STRUCTS) ) {
  918.         if( item->Flags & ITEMTEXT ) {
  919.         (APTR) copyfunc = (APTR) copyIntuiText;
  920.         } else {
  921.         (APTR) copyfunc = (APTR) copyImage;
  922.         }
  923.         if( olditem->ItemFill ) {
  924.         if( !(item->ItemFill = copyfunc(&mymh, olditem->ItemFill,
  925.                         -1, myflags)) ) {
  926.             chainFreeMem( mymh );
  927.             return( NULL );
  928.         }
  929.         }
  930.         if( (item->Flags & HIGHIMAGE) && olditem->SelectFill ) {
  931.         if( !(item->SelectFill = copyfunc(&mymh, olditem->SelectFill,
  932.                         -1, 0L)) ) {
  933.             chainFreeMem( mymh );
  934.             return( NULL );
  935.         }
  936.         }
  937.     }
  938.     if( numsub != 0 && olditem->SubItem ) {
  939.         if( !(item->SubItem = copyMenuItem(&mymh,
  940.                     olditem->SubItem, numsub, 0)) ) {
  941.         chainFreeMem( mymh );
  942.         return( NULL );
  943.         }
  944.     } else {
  945.         item->SubItem = NULL;
  946.     }
  947.     } /* for */
  948.     item->NextItem = NULL;
  949.     if( mymh ) {
  950.     linkChainMem( mhptr, mymh );
  951.     }
  952.     return( menuitem );
  953. } /* copyMenuItem */
  954.  
  955.  
  956. struct Menu *copyMenu( mhptr, oldmenu, nummenu, numitem, numsub, myflags )
  957.     void            **mhptr;
  958.     register struct Menu    *oldmenu;
  959.     SHORT            nummenu, numitem, numsub;
  960.     ULONG            myflags;
  961. {
  962.     register struct Menu    *menu, *temp;
  963.     struct Menu         *menustrip = NULL;
  964.     ULONG            size;
  965.     void            *mymh = NULL;
  966.  
  967. #ifdef GIMME_WIMPY
  968.     if( !mhptr ) {
  969.     return( NULL );
  970.     }
  971. #endif
  972.     menu = NULL;
  973.     for( ; oldmenu && nummenu != 0; oldmenu = oldmenu->NextMenu, --nummenu ) {
  974.     if( !(temp = chainAllocMem(&mymh, (ULONG)sizeof(struct Menu),
  975.                     MEMF_PUBLIC)) ) {
  976.         chainFreeMem( mymh );
  977.         return( NULL );
  978.     }
  979.     if( !menu ) {
  980.         menustrip = temp;
  981.     } else {
  982.         menu->NextMenu = temp;
  983.     }
  984.     menu = temp;
  985.     *menu = *oldmenu;    /* struct copy */
  986.     if( menu->MenuName && !(myflags & GCP_NOT_STRING) ) {
  987.         size = strlen( oldmenu->MenuName );
  988.         if( !(menu->MenuName = chainAllocMem(&mymh, size, MEMF_PUBLIC)) ) {
  989.         if( !(myflags & GCP_SALVAGE) ) {
  990.             chainFreeMem( mymh );
  991.             return( NULL );
  992.         }
  993.         } else {
  994.         /* strcpy( menu->MenuName, oldmenu->MenuName ); */
  995.         movmem( oldmenu->MenuName, menu->MenuName, (int) size + 1 );
  996.         }
  997.     }
  998.     if( numitem != 0 && oldmenu->FirstItem ) {
  999.         if( !(menu->FirstItem = copyMenuItem(&mymh,
  1000.                 oldmenu->FirstItem, numitem, numsub, myflags)) ) {
  1001.         chainFreeMem( mymh );
  1002.         return( NULL );
  1003.         }
  1004.     } else {
  1005.         menu->FirstItem = NULL;
  1006.     }
  1007.     } /* for */
  1008.     menu->NextMenu = NULL;
  1009.     if( mymh ) {
  1010.     linkChainMem( mhptr, mymh );
  1011.     }
  1012.     return( menustrip );
  1013. } /* copyMenu */
  1014. SHAR_EOF
  1015. cat << \SHAR_EOF > dbuf.c
  1016. /*
  1017.  *  FILE: dbuf.c
  1018.  *  Support routines for converting a single-buffered Intuition screen
  1019.  *  into a double-buffered screen and back.
  1020.  *
  1021.  *  Public Domain, but keep my name in it as the original author.
  1022.  *  31-Aug-88    Jan Sven Trabandt   first release version
  1023.  */
  1024.  
  1025.  
  1026. #define I_AM_DBUF
  1027. #include "gimmelib/gimmefuncs.h"
  1028. #include "gimmelib/minterm.h"
  1029.  
  1030.  
  1031. short makeDBuf( screen, bmptr )
  1032.     struct Screen   *screen;
  1033.     struct BitMap   **bmptr;
  1034. {
  1035. #ifdef GIMME_WIMPY
  1036.     if( !screen || !bmptr ) {
  1037.     return( -1 );
  1038.     }
  1039. #endif
  1040.     if( !*bmptr ) {
  1041.     *bmptr = gimmeBitMap( screen->BitMap.Depth, screen->Width,
  1042.                 screen->Height );
  1043.     if( !*bmptr ) {
  1044.         return( -1 );
  1045.     }
  1046.     }
  1047.     screen->RastPort.BitMap = *bmptr;        /* draw to back buffer */
  1048.     return( 0 );
  1049. } /* makeDBuf */
  1050.  
  1051.  
  1052. short unmakeDBuf( screen, bmptr, bm )
  1053.     struct Screen   *screen;
  1054.     struct BitMap   **bmptr;
  1055.     struct BitMap   *bm;
  1056. {
  1057.     struct BitMap   *viewbm;
  1058.  
  1059. #ifdef GIMME_WIMPY
  1060.     if( !screen || !bmptr ) {
  1061.     return( -1 );
  1062.     }
  1063. #endif
  1064.     viewbm = screen->ViewPort.RasInfo->BitMap;
  1065.     if( !(screen->Flags & CUSTOMBITMAP) && viewbm == *bmptr ) {
  1066.     BltBitMap( viewbm, 0L, 0L, screen->RastPort.BitMap, 0L, 0L,
  1067.             (ULONG)(bm->BytesPerRow) << 3, (ULONG) bm->Rows,
  1068.             (ULONG) GIM_MINTERM_COPY, 0x0ffL, NULL );
  1069.     swapDBuf( screen, GIM_MINTERM_DEST );
  1070.     }
  1071.     if( viewbm != screen->RastPort.BitMap ) {
  1072.     screen->RastPort.BitMap = viewbm;
  1073.     }
  1074.     if( bm ) {
  1075.     getRidOfBitMap( bm );
  1076.     }
  1077.     return( 0 );
  1078. } /* unmakeDBuf */
  1079.  
  1080.  
  1081. short swapDBuf( screen, minterm )
  1082.     register struct Screen  *screen;
  1083.     SHORT   minterm;
  1084. {
  1085.     struct BitMap   *bm;
  1086.  
  1087. #ifdef GIMME_WIMPY
  1088.     if( !screen ) {
  1089.     return( -1 );
  1090.     }
  1091. #endif
  1092.     Forbid();
  1093.     bm = screen->ViewPort.RasInfo->BitMap;
  1094.     if( bm == screen->RastPort.BitMap ) {
  1095.     Permit();
  1096.     return( 0 );
  1097.     }
  1098.     screen->ViewPort.RasInfo->BitMap = screen->RastPort.BitMap;
  1099.     screen->RastPort.BitMap = bm;
  1100.     Permit();
  1101.     MakeScreen( screen );
  1102.     RethinkDisplay();
  1103.     if( minterm != GIM_MINTERM_DEST ) {
  1104.     BltBitMap( screen->ViewPort.RasInfo->BitMap, 0L, 0L, bm, 0L, 0L,
  1105.             (ULONG)(bm->BytesPerRow) << 3, (ULONG) bm->Rows,
  1106.             (ULONG) minterm, 0x0ffL, NULL );
  1107.     }
  1108.     return( 0 );
  1109. } /* swapDBuf */
  1110. SHAR_EOF
  1111. cat << \SHAR_EOF > dbufquick.c
  1112. /*
  1113.  *  FILE: dbufquick.c
  1114.  *  Support routines for converting a single-buffered Intuition screen
  1115.  *  into a double-buffered screen and back.
  1116.  *  It is faster than dbuf.c because copper lists are stored and manipulated
  1117.  *  quickly by these routines.
  1118.  *
  1119.  *  NOTE: these routines are not very forgiving with respect to moving the
  1120.  *  screen around under Intuition.
  1121.  *
  1122.  *  Public Domain, but keep my name in it as the original author.
  1123.  *  31-Aug-88    Jan Sven Trabandt   first release version
  1124.  */
  1125.  
  1126.  
  1127. #define I_AM_DBUFQUICK
  1128. #include "gimmelib/gimmefuncs.h"
  1129. #include "gimmelib/minterm.h"
  1130.  
  1131.  
  1132. short makeDBufQuick( screen, bmptr, lcprptr, scprptr )
  1133.     struct Screen   *screen;
  1134.     struct BitMap   **bmptr;
  1135.     struct cprlist  **lcprptr, **scprptr;
  1136. {
  1137.     struct BitMap   *bm;
  1138.     struct cprlist  *lcpr, *scpr;
  1139.     struct View     *view;
  1140.  
  1141. #ifdef GIMME_WIMPY
  1142.     if( !screen || !bmptr || !lcprptr || !scprptr ) {
  1143.     return( -1 );
  1144.     }
  1145. #endif
  1146.     if( !*bmptr ) {
  1147.     *bmptr = gimmeBitMap( screen->BitMap.Depth, screen->Width,
  1148.                 screen->Height );
  1149.     if( !*bmptr ) {
  1150.         return( -1 );
  1151.     }
  1152.     }
  1153.  
  1154.     Forbid();
  1155.     bm = screen->RastPort.BitMap;        /* save main bitmap pointer */
  1156.     view = ViewAddress();
  1157.     lcpr = view->LOFCprList;            /* save these copper lists */
  1158.     scpr = view->SHFCprList;
  1159.     view->LOFCprList = NULL;
  1160.     view->SHFCprList = NULL;
  1161.     screen->ViewPort.RasInfo->BitMap = *bmptr;        /* set to back buffer */
  1162.     MakeScreen( screen );
  1163.     MrgCop( view );                         /* make new copper lists */
  1164.     *lcprptr = view->LOFCprList;        /* save new copper lists */
  1165.     *scprptr = view->SHFCprList;
  1166.     view->LOFCprList = lcpr;            /* restore old copper lists */
  1167.     view->SHFCprList = scpr;
  1168.     screen->ViewPort.RasInfo->BitMap = bm;  /* restore main viewing buffer */
  1169.     Permit();
  1170.  
  1171.     screen->RastPort.BitMap = *bmptr;        /* draw to back buffer */
  1172.     return( 0 );
  1173. } /* makeDBufQuick */
  1174.  
  1175.  
  1176. short unmakeDBufQuick( screen, bmptr, bm, lcprptr, scprptr )
  1177.     struct Screen   *screen;
  1178.     struct BitMap   **bmptr;
  1179.     struct BitMap   *bm;
  1180.     struct cprlist  **lcprptr, **scprptr;
  1181. {
  1182.     struct BitMap   *viewbm;
  1183.  
  1184. #ifdef GIMME_WIMPY
  1185.     if( !screen || !bmptr || !lcprptr || !scprptr ) {
  1186.     return( -1 );
  1187.     }
  1188. #endif
  1189.     viewbm = screen->ViewPort.RasInfo->BitMap;
  1190.     if( !(screen->Flags & CUSTOMBITMAP) && viewbm == *bmptr ) {
  1191.     BltBitMap( viewbm, 0L, 0L, screen->RastPort.BitMap, 0L, 0L,
  1192.             (ULONG)(bm->BytesPerRow) << 3, (ULONG) bm->Rows,
  1193.             (ULONG) GIM_MINTERM_COPY, 0x0ffL, NULL );
  1194.     swapDBufQuick( screen, GIM_MINTERM_DEST, lcprptr, scprptr );
  1195.     }
  1196.     if( viewbm != screen->RastPort.BitMap ) {
  1197.     screen->RastPort.BitMap = viewbm;
  1198.     }
  1199.     if( bm ) {
  1200.     getRidOfBitMap( bm );
  1201.     }
  1202.     if( *lcprptr ) {
  1203.     FreeCprList( *lcprptr );
  1204.     }
  1205.     if( *scprptr ) {
  1206.     FreeCprList( *scprptr );
  1207.     }
  1208.     return( 0 );
  1209. } /* unmakeDBufQuick */
  1210.  
  1211.  
  1212. short swapDBufQuick( screen, minterm, lcprptr, scprptr )
  1213.     register struct Screen  *screen;
  1214.     SHORT   minterm;
  1215.     struct cprlist  **lcprptr, **scprptr;
  1216. {
  1217.     struct BitMap   *bm;
  1218.     struct cprlist  *lcpr, *scpr;
  1219.     struct View     *view;
  1220.  
  1221. #ifdef GIMME_WIMPY
  1222.     if( !screen || !lcprptr || !scprptr || !*lcprptr || !*scprptr ) {
  1223.     return( -1 );
  1224.     }
  1225. #endif
  1226.     Forbid();
  1227.     bm = screen->ViewPort.RasInfo->BitMap;
  1228.     if( bm == screen->RastPort.BitMap ) {
  1229.     Permit();
  1230.     return( 0 );
  1231.     }
  1232.     view = ViewAddress();
  1233.     lcpr = view->LOFCprList;            /* get current copper lists */
  1234.     scpr = view->SHFCprList;
  1235.     view->LOFCprList = *lcprptr;        /* set other copper lists */
  1236.     view->SHFCprList = *scprptr;
  1237.     *lcprptr = lcpr;                /* save new other copper lists */
  1238.     *scprptr = scpr;
  1239.     LoadView( view );
  1240.  
  1241.     screen->ViewPort.RasInfo->BitMap = screen->RastPort.BitMap;
  1242.     screen->RastPort.BitMap = bm;
  1243.     Permit();
  1244.     if( minterm != GIM_MINTERM_DEST ) {
  1245.     BltBitMap( screen->ViewPort.RasInfo->BitMap, 0L, 0L, bm, 0L, 0L,
  1246.             (ULONG)(bm->BytesPerRow) << 3, (ULONG) bm->Rows,
  1247.             (ULONG) minterm, 0x0ffL, NULL );
  1248.     }
  1249.     return( 0 );
  1250. } /* swapDBufQuick */
  1251. SHAR_EOF
  1252. cat << \SHAR_EOF > dbufvquick.c
  1253. /*
  1254.  *  FILE: dbufvquick.c
  1255.  *  Support routines for converting a single-buffered Intuition screen
  1256.  *  into a double-buffered screen and back.
  1257.  *  It is faster than dbuf.c because copper lists are stored and manipulated
  1258.  *  quickly by these routines.
  1259.  *  It is slightly faster than dbufquick.c because copper lis pointers do not
  1260.  *  need to be passed as extra parameters.
  1261.  *
  1262.  *  NOTE: these routines are not very forgiving with respect to moving the
  1263.  *  screen around under Intuition.
  1264.  *
  1265.  *  Public Domain, but keep my name in it as the original author.
  1266.  *  31-Aug-88    Jan Sven Trabandt   first release version
  1267.  */
  1268.  
  1269.  
  1270. #define I_AM_DBUFVQUICK
  1271. #include "gimmelib/gimmefuncs.h"
  1272. #include "gimmelib/minterm.h"
  1273.  
  1274. static struct View    *gimView = NULL;
  1275. static struct cprlist    *gimShCpr = NULL;
  1276. static struct cprlist    *gimLoCpr = NULL;
  1277.  
  1278.  
  1279. short makeDBufVQuick( screen, bmptr )
  1280.     struct Screen   *screen;
  1281.     struct BitMap   **bmptr;
  1282. {
  1283.     struct BitMap   *bm;
  1284.     struct cprlist  *lcpr, *scpr;
  1285.  
  1286. #ifdef GIMME_WIMPY
  1287.     if( !screen || !bmptr ) {
  1288.     return( -1 );
  1289.     }
  1290. #endif
  1291.     if( !*bmptr ) {
  1292.     *bmptr = gimmeBitMap( screen->BitMap.Depth, screen->Width,
  1293.                 screen->Height );
  1294.     if( !*bmptr ) {
  1295.         return( -1 );
  1296.     }
  1297.     }
  1298.  
  1299.     Forbid();
  1300.     bm = screen->RastPort.BitMap;        /* save main bitmap pointer */
  1301.     gimView = ViewAddress();
  1302.     lcpr = gimView->LOFCprList;            /* save these copper lists */
  1303.     scpr = gimView->SHFCprList;
  1304.     gimView->LOFCprList = NULL;
  1305.     gimView->SHFCprList = NULL;
  1306.     screen->ViewPort.RasInfo->BitMap = *bmptr;        /* set to back buffer */
  1307.     MakeScreen( screen );
  1308.     MrgCop( gimView );                         /* make new copper lists */
  1309.     gimLoCpr = gimView->LOFCprList;           /* save new copper lists */
  1310.     gimShCpr = gimView->SHFCprList;
  1311.     gimView->LOFCprList = lcpr;            /* restore old copper lists */
  1312.     gimView->SHFCprList = scpr;
  1313.     screen->ViewPort.RasInfo->BitMap = bm;  /* restore main viewing buffer */
  1314.     Permit();
  1315.  
  1316.     screen->RastPort.BitMap = *bmptr;        /* draw to back buffer */
  1317.     return( 0 );
  1318. } /* makeDBufVQuick */
  1319.  
  1320.  
  1321. short unmakeDBufVQuick( screen, bmptr, bm )
  1322.     struct Screen   *screen;
  1323.     struct BitMap   **bmptr;
  1324.     struct BitMap   *bm;
  1325. {
  1326.     struct BitMap   *viewbm;
  1327.  
  1328. #ifdef GIMME_WIMPY
  1329.     if( !screen || !bmptr ) {
  1330.     return( -1 );
  1331.     }
  1332. #endif
  1333.     viewbm = screen->ViewPort.RasInfo->BitMap;
  1334.     if( !(screen->Flags & CUSTOMBITMAP) && viewbm == *bmptr ) {
  1335.     BltBitMap( viewbm, 0L, 0L, screen->RastPort.BitMap, 0L, 0L,
  1336.             (ULONG)(bm->BytesPerRow) << 3, (ULONG) bm->Rows,
  1337.             (ULONG) GIM_MINTERM_COPY, 0x0ffL, NULL );
  1338.     swapDBufVQuick( screen, GIM_MINTERM_DEST );
  1339.     }
  1340.     if( viewbm != screen->RastPort.BitMap ) {
  1341.     screen->RastPort.BitMap = viewbm;
  1342.     }
  1343.     if( bm ) {
  1344.     getRidOfBitMap( bm );
  1345.     }
  1346.     if( gimLoCpr ) {
  1347.     FreeCprList( gimLoCpr );
  1348.     }
  1349.     if( gimShCpr ) {
  1350.     FreeCprList( gimShCpr );
  1351.     }
  1352.     return( 0 );
  1353. } /* unmakeDBufVQuick */
  1354.  
  1355.  
  1356. short swapDBufVQuick( screen, minterm )
  1357.     register struct Screen  *screen;
  1358.     SHORT   minterm;
  1359. {
  1360.     struct BitMap   *bm;
  1361.     struct cprlist  *lcpr, *scpr;
  1362.  
  1363. #ifdef GIMME_WIMPY
  1364.     if( !screen ) {
  1365.     return( -1 );
  1366.     }
  1367. #endif
  1368.     Forbid();
  1369.     bm = screen->ViewPort.RasInfo->BitMap;
  1370.     if( bm == screen->RastPort.BitMap ) {
  1371.     Permit();
  1372.     return( 0 );
  1373.     }
  1374.     lcpr = gimView->LOFCprList;            /* get current copper lists */
  1375.     scpr = gimView->SHFCprList;
  1376.     gimView->LOFCprList = gimLoCpr;           /* set other copper lists */
  1377.     gimView->SHFCprList = gimShCpr;
  1378.     gimLoCpr = lcpr;                /* save new other copper lists */
  1379.     gimShCpr = scpr;
  1380.     LoadView( gimView );
  1381.  
  1382.     screen->ViewPort.RasInfo->BitMap = screen->RastPort.BitMap;
  1383.     screen->RastPort.BitMap = bm;
  1384.     Permit();
  1385.     if( minterm != GIM_MINTERM_DEST ) {
  1386.     BltBitMap( screen->ViewPort.RasInfo->BitMap, 0L, 0L, bm, 0L, 0L,
  1387.             (ULONG)(bm->BytesPerRow) << 3, (ULONG) bm->Rows,
  1388.             (ULONG) minterm, 0x0ffL, NULL );
  1389.     }
  1390.     return( 0 );
  1391. } /* swapDBufVQuick */
  1392. SHAR_EOF
  1393. cat << \SHAR_EOF > dualpf.c
  1394. /*
  1395.  *  FILE: dualpf.c
  1396.  *  Support routines for converting a single-playfield Intuition screen
  1397.  *  into a dual-playfield screen and back.
  1398.  *
  1399.  *  Public Domain, but keep my name in it as the original author.
  1400.  *  31-Aug-88    Jan Sven Trabandt   first release version
  1401.  */
  1402.  
  1403.  
  1404. #include "gimmelib/gimmefuncs.h"
  1405.  
  1406.  
  1407. short makeDualPlayfield( screen, ri, reldepth )
  1408.     struct Screen   *screen;
  1409.     struct RasInfo  *ri;
  1410.     SHORT        reldepth;
  1411. {
  1412.     SHORT   depth;
  1413.  
  1414. #ifdef GIMME_WIMPY
  1415.     if( !screen ) {
  1416.     return( -1 );
  1417.     }
  1418. #endif
  1419.     if( (screen->ViewPort.Modes & DUALPF)
  1420.     || reldepth < -1 || reldepth > 0 || screen->BitMap.Depth > 3 ) {
  1421.     return( -1 );
  1422.     }
  1423.     depth = screen->BitMap.Depth + reldepth;
  1424.     if( depth > 3 ) {
  1425.     return( -1 );
  1426.     }
  1427.     ri->BitMap = gimmeBitMap( depth, screen->Width, screen->Height );
  1428.     if( !ri->BitMap ) {
  1429.     return( -1 );
  1430.     }
  1431.     ri->Next = NULL;
  1432.     ri->RxOffset = 0;
  1433.     ri->RyOffset = 0;
  1434.     Forbid();
  1435.     screen->ViewPort.RasInfo->Next = ri;
  1436.     screen->ViewPort.Modes |= DUALPF;
  1437.     Permit();
  1438.     MakeScreen( screen );
  1439.     RethinkDisplay();
  1440.     return( 0 );
  1441. } /* makeDualPlayfield */
  1442.  
  1443.  
  1444. short unmakeDualPlayfield( screen )
  1445.     struct Screen   *screen;
  1446. {
  1447.     struct RasInfo  *ri;
  1448.     struct BitMap   *bm;
  1449.  
  1450. #ifdef GIMME_WIMPY
  1451.     if( !screen ) {
  1452.     return( -1 );
  1453.     }
  1454. #endif
  1455.     if( !(screen->ViewPort.Modes & DUALPF) ) {
  1456.     return( -1 );
  1457.     }
  1458.     Forbid();
  1459.     ri = screen->ViewPort.RasInfo->Next;
  1460.     bm = ri->BitMap;
  1461.     ri->BitMap = NULL;
  1462.     screen->ViewPort.RasInfo->Next = NULL;
  1463.     screen->ViewPort.Modes &= ~(DUALPF | PFBA);
  1464.     Permit();
  1465.     MakeScreen( screen );
  1466.     RethinkDisplay();
  1467.     if( bm ) {
  1468.     getRidOfBitMap( bm );
  1469.     }
  1470.     return( 0 );
  1471. } /* unmakeDualPlayfield */
  1472. SHAR_EOF
  1473. cat << \SHAR_EOF > font.c
  1474. /*
  1475.  *  FILE: font.c
  1476.  *  Support routines for accessign ROM or disk-based fonts.
  1477.  *
  1478.  *  Public Domain, but keep my name in it as the original author.
  1479.  *  31-Aug-88    Jan Sven Trabandt   first release version
  1480.  *  30-Sep-88    Jan Sven Trabandt   gimmeFont now alters given TextAttr
  1481.  *  31-Oct-88    Jan Sven Trabandt   added gimmeFontLazy
  1482.  */
  1483.  
  1484.  
  1485. #include "gimmelib/gimmefuncs.h"
  1486.  
  1487.  
  1488. struct TextFont *gimmeFont( textattr )
  1489.     struct TextAttr *textattr;
  1490. {
  1491.     struct TextFont *tf;
  1492.  
  1493. #ifdef GIMME_WIMPY
  1494.     if( !textattr ) {
  1495.     return( NULL );
  1496.     }
  1497. #endif
  1498.     tf = OpenDiskFont( textattr );
  1499.     if( tf ) {
  1500.     textattr->ta_YSize = tf->tf_YSize;
  1501.     textattr->ta_Style = tf->tf_Style;
  1502.     }
  1503.     return( tf );
  1504. } /* gimmeFont */
  1505.  
  1506.  
  1507. struct TextFont *gimmeFontLazy( name, size )
  1508.     UBYTE   *name;
  1509.     UWORD   size;
  1510. {
  1511.     struct TextAttr ta;
  1512.  
  1513. #ifdef GIMME_WIMPY
  1514.     if( !name ) {
  1515.     return( NULL );
  1516.     }
  1517. #endif
  1518.     ta.ta_Name = (STRPTR) name;
  1519.     ta.ta_YSize = size;
  1520.     ta.ta_Style = FS_NORMAL;
  1521.     ta.ta_Flags = FPF_DISKFONT;
  1522.     return( OpenDiskFont(&ta) );
  1523. } /* gimmeFontLazy */
  1524.  
  1525.  
  1526. short getRidOfFont( textfont )
  1527.     struct TextFont *textfont;
  1528. {
  1529. #ifdef GIMME_WIMPY
  1530.     if( !textfont ) {
  1531.     return( -1 );
  1532.     }
  1533. #endif
  1534.     CloseFont( textfont );
  1535.     return( 0 );
  1536. } /* getRidOfFont */
  1537. SHAR_EOF
  1538. cat << \SHAR_EOF > gadget.c
  1539. /*
  1540.  *  FILE: gadget.c
  1541.  *  Support routines for creating and dealing with gadgets.
  1542.  *
  1543.  *  Public Domain, but keep my name in it as the original author.
  1544.  *  31-Aug-88    Jan Sven Trabandt   first release version
  1545.  *  30-Sep-88    Jan Sven Trabandt   enhanced routines
  1546.  *                    renamed getRidOfGadget to getRidOfGadgets
  1547.  *  31-Oct-88    Jan Sven Trabandt   keep up with clearGadgets change
  1548.  *                    moved toggleBoolGadget to gadgstuff.c
  1549.  */
  1550.  
  1551.  
  1552. #define I_AM_GADGET
  1553. #include "gimmelib/gimmefuncs.h"
  1554. #include "gimmelib/gadget.h"
  1555. #include "gimmelib/postext.h"
  1556. #include <graphics/gfxbase.h>
  1557. #define GIM_BUILTIN
  1558. #include "gimmelib/macros.h"
  1559.  
  1560. extern struct GfxBase *GfxBase;
  1561.  
  1562. /* one undo buffer is safe for several string gadgets since under Intuition
  1563.  * only one string gadget can be truly active at any time (see manual)
  1564. static UBYTE defaultUndoBuffer[GIM_DFLT_UNDO_BUF_SIZE];
  1565.  
  1566.  
  1567. short getRidOfGadgets( gp )
  1568.     register struct Gadget  *gp;
  1569. {
  1570.     struct Gadget   *temp;
  1571.  
  1572.     while( gp ) {
  1573.     temp = gp->NextGadget;
  1574.     if( gp->UserData ) {
  1575.         chainFreeMem( gp->UserData );
  1576.     }
  1577.     gp = temp;
  1578.     } /* while */
  1579.     return( 0 );
  1580. } /* getRidOfGadgets */
  1581.  
  1582.  
  1583. struct Gadget *gimmeBoolGadget( window, id, left, top, xsize, ysize, s, s2,
  1584.                     textattr, myflags )
  1585.     struct Window   *window;
  1586.     USHORT        id;
  1587.     SHORT        left, top;
  1588.     register SHORT  xsize, ysize;
  1589.     UBYTE        *s, *s2;
  1590.     struct TextAttr *textattr;
  1591.     ULONG        myflags;
  1592. {
  1593.     register struct Gadget  *gp;
  1594.     struct IntuiText        *itp, *spitp;
  1595.     struct Border        *bp;
  1596.     UBYTE   *spstr;
  1597.     void    *gadgmh = NULL;
  1598.     SHORT   wid, tempwid, maxlen;
  1599.     BYTE    fpen, bpen, drawmode, pad;
  1600.     SHORT   i;
  1601.  
  1602.     GUESS
  1603.     QUIF( !id );
  1604.     QUIF( !s );
  1605.  
  1606.     gp = chainAllocMem( &gadgmh, (ULONG)sizeof(struct Gadget),
  1607.                 MEMF_CLEAR | MEMF_PUBLIC );
  1608.     QUIF( !gp );
  1609.     itp = gimmeIntuiText( &gadgmh, s, textattr, 0 );
  1610.     QUIF( !itp );
  1611.     if( window ) {
  1612.         if( (fpen = window->RPort->FgPen) == (BYTE)(-1) ) {
  1613.         fpen = 1;
  1614.         }
  1615.         if( (bpen = window->RPort->BgPen) == (BYTE)(-1) ) {
  1616.         bpen = 0;
  1617.         }
  1618.         drawmode = window->RPort->DrawMode;
  1619.         itp->FrontPen = fpen;
  1620.         itp->BackPen = bpen;
  1621.         itp->DrawMode = drawmode;
  1622.     }
  1623.     wid = IntuiTextLength( itp ) + (HORIZ_SPACE << 1);
  1624.     itp->LeftEdge = HORIZ_SPACE - AROUND_SPACE;
  1625.     itp->TopEdge = AROUND_SPACE;
  1626.     gp->GadgetText = itp;
  1627.     if( s2 ) {                      /* toggle type desired */
  1628.         itp = gimmeIntuiText( &gadgmh, s2, textattr, 0 );
  1629.         QUIF( !itp );
  1630.         tempwid = IntuiTextLength( itp ) + (HORIZ_SPACE << 1);
  1631.         itp->LeftEdge = HORIZ_SPACE - AROUND_SPACE;
  1632.         itp->TopEdge = AROUND_SPACE;
  1633.         if( window ) {
  1634.         itp->FrontPen = fpen;
  1635.         itp->BackPen = bpen;
  1636.         itp->DrawMode = drawmode;
  1637.         }
  1638.         spitp = gimmeIntuiText( &gadgmh, " ", textattr, 0 );
  1639.         QUIF( !spitp );
  1640.         if( window ) {
  1641.         spitp->FrontPen = fpen;
  1642.         spitp->BackPen = bpen;
  1643.         spitp->DrawMode = drawmode;
  1644.         }
  1645.         if( tempwid > wid ) {           /* second string is longer */
  1646.         gp->GadgetText->LeftEdge += (tempwid - wid) >> 1;
  1647.         wid = tempwid;
  1648.         maxlen = (wid - (HORIZ_SPACE << 1)) / IntuiTextLength( spitp );
  1649.         *spitp = *itp;        /* struct copy */
  1650.         spitp->NextText = gp->GadgetText;
  1651.         gp->GadgetText = spitp;
  1652.         gp->SelectRender = (APTR) itp;
  1653.         } else {
  1654.         itp->LeftEdge += (wid - tempwid) >> 1;
  1655.         maxlen = (wid - (HORIZ_SPACE << 1)) / IntuiTextLength( spitp );
  1656.         *spitp = *(gp->GadgetText);         /* struct copy */
  1657.         spitp->NextText = itp;
  1658.         gp->SelectRender = (APTR) spitp;
  1659.         }
  1660.         spstr = (UBYTE *) chainAllocMem( &gadgmh,
  1661.                 (LONG)((maxlen+1) * sizeof(UBYTE)), MEMF_PUBLIC );
  1662.         QUIF( !spstr );
  1663.         spstr[maxlen] = '\0';
  1664.         for( i = maxlen; --i >= 0; ) {
  1665.         spstr[i] = ' ';
  1666.         } /* for */
  1667.         spitp->IText = spstr;
  1668.         /* use SelectRender since not using GADGHIMAGE so it's safe */
  1669.         gp->Flags = GADGHNONE;
  1670.         gp->Activation = GADGIMMEDIATE | TOGGLESELECT;
  1671.     } else {
  1672.         gp->Flags = GADGHCOMP;
  1673.         gp->Activation = RELVERIFY;
  1674.     }
  1675.     if( xsize <= 0 ) {
  1676.         xsize = wid;
  1677.     }
  1678.     if( ysize <= 0 ) {
  1679.         if( textattr ) {
  1680.         ysize = textattr->ta_YSize;
  1681.         } else if( window ) {
  1682.         ysize = window->RPort->TxHeight;
  1683.         } else {
  1684.         ysize = GfxBase->DefaultFont->tf_YSize;
  1685.         }
  1686.         ysize += VERT_SPACE << 1;
  1687.     }
  1688.  
  1689.     if( xsize == wid ) {            /* if xsize was exact or <= 0 */
  1690.         tempwid = -wid;
  1691.     } else {
  1692.         tempwid = xsize - wid;
  1693.         if( !(myflags & GPT_FULLWIDTH) ) {
  1694.         xsize -= tempwid;
  1695.         }
  1696.     }
  1697.     switch( myflags & GPT_XFLAGS ) {
  1698.       case GPT_XCENTRE:
  1699.         left += tempwid >> 1;
  1700.         break;
  1701.       case GPT_XRIGHT:        /* right-align if width was given */
  1702.         left += tempwid;
  1703.       case GPT_XLEFT:
  1704.       default:
  1705.         break;
  1706.     } /* switch */
  1707.  
  1708.     switch( myflags & GPT_YFLAGS ) {
  1709.       case GPT_YBOTTOM:
  1710.         top -= ysize;
  1711.         break;
  1712.       case GPT_YCENTRE:
  1713.       case GPT_YCENTREBASE:     /* approx */
  1714.         top -= ysize >> 1;
  1715.         break;
  1716.       case GPT_YBASELINE:        /* approx */
  1717.         top -= ysize - (VERT_SPACE << 1);
  1718.         break;
  1719.       case GPT_YTOP:
  1720.       default:
  1721.         break;
  1722.     } /* switch */
  1723.     gp->LeftEdge = left + AROUND_SPACE;
  1724.     gp->TopEdge = top + AROUND_SPACE;
  1725.     gp->Width = xsize - (AROUND_SPACE << 1);
  1726.     gp->Height = ysize - (AROUND_SPACE << 1);
  1727.     bp = gimmeBorder( &gadgmh, xsize, ysize );
  1728.     QUIF( !bp );
  1729.     bp->LeftEdge = - AROUND_SPACE;
  1730.     bp->TopEdge = - AROUND_SPACE;
  1731.     if( window ) {
  1732.         bp->FrontPen = fpen;
  1733.         bp->BackPen = bpen;
  1734.         bp->DrawMode = drawmode;
  1735.     }
  1736.     gp->GadgetType = BOOLGADGET;
  1737.     gp->GadgetRender = (APTR) bp;
  1738.     if( window ) {
  1739.         if( window->Flags & GIMMEZEROZERO ) {
  1740.         gp->GadgetType |= GZZGADGET;
  1741.         }
  1742.     }
  1743.     gp->GadgetID = id;
  1744.     gp->UserData = gadgmh;
  1745.     return( gp );
  1746.     ENDGUESS
  1747.     if( gadgmh ) {
  1748.     chainFreeMem( gadgmh );
  1749.     }
  1750.     return( NULL );
  1751. } /* gimmeBoolGadget */
  1752.  
  1753.  
  1754. struct Gadget *gimmeBoolImageGadget( window, id, left, top, depth, width,
  1755.                     height, myflags, dep2, wid2, ht2 )
  1756.     struct Window   *window;
  1757.     USHORT        id;
  1758.     SHORT        left, top;
  1759.     SHORT        depth, width, height;
  1760.     ULONG        myflags;
  1761.     SHORT        dep2, wid2, ht2;
  1762. {
  1763.     register struct Gadget  *gp;
  1764.     UBYTE   *spstr;
  1765.     void    *gadgmh = NULL;
  1766.  
  1767.     GUESS
  1768.     QUIF( !id );
  1769.  
  1770.     gp = chainAllocMem( &gadgmh, (ULONG)sizeof(struct Gadget),
  1771.                 MEMF_CLEAR | MEMF_PUBLIC );
  1772.     QUIF( !gp );
  1773.     gp->GadgetRender = (APTR) gimmeImage( &gadgmh, depth, width, height );
  1774.     QUIF( !gp->GadgetRender );
  1775.     if( dep2 > 0 && wid2 > 0 && ht2 > 0 ) {
  1776.         gp->SelectRender = (APTR) gimmeImage( &gadgmh, dep2, wid2, ht2 );
  1777.         QUIF( !gp->SelectRender );
  1778.         gp->Flags = GADGIMAGE | GADGHIMAGE;
  1779.         gp->Activation = GADGIMMEDIATE | TOGGLESELECT;
  1780.     } else {
  1781.         gp->Flags = GADGIMAGE | GADGHCOMP;
  1782.         gp->Activation = RELVERIFY;
  1783.     }
  1784.     switch( myflags & GPT_XFLAGS ) {
  1785.       case GPT_XCENTRE:
  1786.         left -= width >> 1;
  1787.         break;
  1788.       case GPT_XRIGHT:
  1789.         left -= width;
  1790.       case GPT_XLEFT:
  1791.       default:
  1792.         break;
  1793.     } /* switch */
  1794.     switch( myflags & GPT_YFLAGS ) {
  1795.       case GPT_YBOTTOM:
  1796.       case GPT_YBASELINE:        /* no "real" meaning, so use bottom */
  1797.         top -= height;
  1798.         break;
  1799.       case GPT_YCENTRE:
  1800.       case GPT_YCENTREBASE:     /* no "real" meaning, so use centre */
  1801.         top -= height >> 1;
  1802.         break;
  1803.       case GPT_YTOP:
  1804.       default:
  1805.         break;
  1806.     } /* switch */
  1807.     gp->LeftEdge = left;
  1808.     gp->TopEdge = top;
  1809.     gp->Width = width;
  1810.     gp->Height = height;
  1811.     gp->GadgetType = BOOLGADGET;
  1812.     if( window && (window->Flags & GIMMEZEROZERO) ) {
  1813.         gp->GadgetType |= GZZGADGET;
  1814.     }
  1815.     gp->GadgetID = id;
  1816.     gp->UserData = gadgmh;
  1817.     return( gp );
  1818.     ENDGUESS
  1819.     if( gadgmh ) {
  1820.     chainFreeMem( gadgmh );
  1821.     }
  1822.     return( NULL );
  1823. } /* gimmeBoolImageGadget */
  1824.  
  1825.  
  1826. struct Gadget *gimmePropGadget( window, id, left, top, xsize, ysize, label,
  1827.                 textattr, activflags, propflags )
  1828.     struct Window   *window;
  1829.     USHORT        id;
  1830.     SHORT        left, top, xsize, ysize;
  1831.     UBYTE        *label;
  1832.     struct TextAttr *textattr;
  1833.     ULONG        activflags, propflags;
  1834. {
  1835.     register struct Gadget  *gp;
  1836.     SHORT   len;
  1837.     BYTE    fpen, bpen;
  1838.     void    *gadgmh = NULL;
  1839.  
  1840.     GUESS
  1841.     QUIF( !id );
  1842.     gp = chainAllocMem( &gadgmh, (ULONG)sizeof(struct Gadget),
  1843.                 MEMF_CLEAR | MEMF_PUBLIC );
  1844.     QUIF( !gp );
  1845.     gp->SpecialInfo = (APTR) gimmePropInfo( &gadgmh, propflags );
  1846.     QUIF( !gp->SpecialInfo );
  1847.     gp->LeftEdge = left;
  1848.     gp->TopEdge = top;
  1849.     if( label ) {
  1850.         gp->GadgetText = gimmeIntuiText( &gadgmh, label, textattr, 0 );
  1851.         QUIF( !gp->GadgetText );
  1852.         len = IntuiTextLength( gp->GadgetText ) + HORIZ_SPACE;
  1853.         gp->GadgetText->LeftEdge = -len;
  1854.         gp->LeftEdge += len;
  1855.         gp->GadgetText->FrontPen = 1;
  1856.         gp->GadgetText->BackPen = 0;
  1857.         if( window ) {
  1858.         if( (fpen = window->RPort->FgPen) != (BYTE)(-1) ) {
  1859.             gp->GadgetText->FrontPen = fpen;
  1860.         }
  1861.         if( (bpen = window->RPort->BgPen) != (BYTE)(-1) ) {
  1862.             gp->GadgetText->BackPen = bpen;
  1863.         }
  1864.         gp->GadgetText->DrawMode = window->RPort->DrawMode;
  1865.         }
  1866.     }
  1867.     gp->Width = xsize;
  1868.     gp->Height = ysize;
  1869.     gp->Flags = GADGHCOMP | GADGIMAGE;
  1870.     gp->Activation = RELVERIFY | activflags;
  1871.     gp->GadgetType = PROPGADGET;
  1872.     gp->GadgetRender = chainAllocMem( &gadgmh, (ULONG)sizeof(struct Image),
  1873.                         MEMF_CLEAR | MEMF_PUBLIC );
  1874.     QUIF( !gp->GadgetRender );
  1875.     if( window && (window->Flags & GIMMEZEROZERO) ) {
  1876.         gp->GadgetType |= GZZGADGET;
  1877.     }
  1878.     gp->GadgetID = id;
  1879.     gp->UserData = gadgmh;
  1880.     return( gp );
  1881.     ENDGUESS
  1882.     if( gadgmh ) {
  1883.     chainFreeMem( gadgmh );
  1884.     }
  1885.     return( NULL );
  1886. } /* gimmePropGadget */
  1887.  
  1888.  
  1889. struct PropInfo *gimmePropInfo( mh, flags )
  1890.     void    **mh;
  1891.     ULONG   flags;
  1892. {
  1893.     register struct PropInfo    *pip;
  1894.  
  1895.     pip = chainAllocMem( mh, (ULONG)sizeof(struct PropInfo),
  1896.                 MEMF_PUBLIC | MEMF_CLEAR );
  1897.     if( pip ) {
  1898.     pip->Flags = AUTOKNOB | flags;
  1899.     pip->HorizBody = 1;
  1900.     pip->VertBody = 1;
  1901.     }
  1902.     return( pip );
  1903. } /* gimmePropInfo */
  1904.  
  1905.  
  1906. struct Gadget *gimmeStringGadget( window, id, left, top, width, maxbuf,
  1907.                     initstr, label, textattr, activflags )
  1908.     struct Window   *window;
  1909.     USHORT        id;
  1910.     SHORT        left, top, width;
  1911.     SHORT        maxbuf;
  1912.     UBYTE        *initstr, *label;
  1913.     struct TextAttr *textattr;
  1914.     ULONG        activflags;
  1915. {
  1916.     register struct Gadget  *gp;
  1917.     struct Border   *bp;
  1918.     SHORT   xsize, ysize;
  1919.     SHORT   len;
  1920.     BYTE    fpen, bpen, drawmode, pad;
  1921.     void    *gadgmh = NULL;
  1922.  
  1923.     GUESS
  1924.     QUIF( !id );
  1925.     gp = chainAllocMem( &gadgmh, (ULONG)sizeof(struct Gadget),
  1926.                 MEMF_CLEAR | MEMF_PUBLIC );
  1927.     QUIF( !gp );
  1928.     gp->SpecialInfo = (APTR) gimmeStringInfo( &gadgmh, maxbuf, initstr,
  1929.                             activflags );
  1930.     QUIF( !gp->SpecialInfo );
  1931.     if( window ) {
  1932.         if( (fpen = window->RPort->FgPen) == (BYTE)(-1) ) {
  1933.         fpen = 1;
  1934.         }
  1935.         if( (bpen = window->RPort->BgPen) == (BYTE)(-1) ) {
  1936.         bpen = 0;
  1937.         }
  1938.         drawmode = window->RPort->DrawMode;
  1939.     }
  1940.     if( textattr ) {
  1941.         ysize = textattr->ta_YSize;
  1942.     } else if( window ) {
  1943.         ysize = window->WScreen->Font->ta_YSize;
  1944.     } else {
  1945.         ysize = GfxBase->DefaultFont->tf_YSize;
  1946.     }
  1947.     ysize += VERT_SPACE << 1;
  1948.     gp->LeftEdge = left + HORIZ_SPACE;
  1949.     gp->TopEdge = top + VERT_SPACE;
  1950.     if( label ) {
  1951.         gp->GadgetText = gimmeIntuiText( &gadgmh, label, textattr, 0 );
  1952.         QUIF( !gp->GadgetText );
  1953.         len = IntuiTextLength( gp->GadgetText ) + (HORIZ_SPACE << 1);
  1954.         gp->GadgetText->LeftEdge = -len;
  1955.         if( window ) {
  1956.         gp->GadgetText->FrontPen = fpen;
  1957.         gp->GadgetText->BackPen = bpen;
  1958.         gp->GadgetText->DrawMode = drawmode;
  1959.         }
  1960.         width -= len;
  1961.         gp->LeftEdge += len - HORIZ_SPACE;
  1962.     }
  1963.     gp->Width = width - HORIZ_SPACE - 1;
  1964.     gp->Height = ysize - VERT_SPACE - 1;
  1965.     bp = gimmeBorder( &gadgmh, width, ysize );
  1966.     /* QUIF( !bp ); */
  1967.     bp->LeftEdge = - HORIZ_SPACE;
  1968.     bp->TopEdge = - VERT_SPACE;
  1969.     if( window ) {
  1970.         bp->FrontPen = fpen;
  1971.         bp->BackPen = bpen;
  1972.         bp->DrawMode = drawmode;
  1973.     }
  1974.     gp->Flags = GADGHCOMP;
  1975.     gp->Activation = RELVERIFY | activflags;
  1976.     gp->GadgetType = STRGADGET;
  1977.     gp->GadgetRender = (APTR) bp;
  1978.     if( window && (window->Flags & GIMMEZEROZERO) ) {
  1979.         gp->GadgetType |= GZZGADGET;
  1980.     }
  1981.     gp->GadgetID = id;
  1982.     gp->UserData = gadgmh;
  1983.     return( gp );
  1984.     ENDGUESS
  1985.     if( gadgmh ) {
  1986.     chainFreeMem( gadgmh );
  1987.     }
  1988.     return( NULL );
  1989. } /* gimmeStringGadget */
  1990.  
  1991.  
  1992. struct StringInfo *gimmeStringInfo( mh, bufsize, s, flags )
  1993.     void    **mh;
  1994.     SHORT   bufsize;
  1995.     UBYTE   *s;
  1996.     ULONG   flags;
  1997. {
  1998.     register struct StringInfo    *sip;
  1999.     UBYTE   tempchar;
  2000.     short   len;
  2001.     void    *mymh = NULL;
  2002.  
  2003.     GUESS
  2004.     sip = chainAllocMem( &mymh, (ULONG)sizeof(struct StringInfo),
  2005.                 MEMF_PUBLIC | MEMF_CLEAR );
  2006.     QUIF( !sip );
  2007.     sip->Buffer = chainAllocMem( &mymh, (LONG) bufsize,
  2008.                     MEMF_PUBLIC | MEMF_CLEAR );
  2009.     QUIF( !sip->Buffer );
  2010.     if( bufsize <= GIM_DFLT_UNDO_BUF_SIZE ) {
  2011.         sip->UndoBuffer = defaultUndoBuffer;
  2012.     } else {
  2013.         sip->UndoBuffer = chainAllocMem( &mymh, (LONG) bufsize,
  2014.                     MEMF_PUBLIC | MEMF_CLEAR );
  2015.         QUIF( !sip->UndoBuffer );
  2016.     }
  2017.     sip->MaxChars = bufsize--;
  2018.     len = strlen( s );
  2019.     --bufsize;
  2020.     if( len > bufsize ) {           /* make sure string not too long */
  2021.         tempchar = s[bufsize];
  2022.         s[bufsize] = '\0';
  2023.     }
  2024.     strcpy( sip->Buffer, s );
  2025.     if( len > bufsize ) {
  2026.         s[bufsize] = tempchar;
  2027.     }
  2028.     if( flags & LONGINT ) {
  2029.         sip->LongInt = atol( s );
  2030.     }
  2031.     linkChainMem( mh, mymh );
  2032.     return( sip );
  2033.     ENDGUESS
  2034.     if( mymh ) {
  2035.     chainFreeMem( mymh );
  2036.     }
  2037.     return( NULL );
  2038. } /* gimmeStringInfo */
  2039. SHAR_EOF
  2040. cat << \SHAR_EOF > gadgstuff.c
  2041. /*
  2042.  *  FILE: gadgstuff.c
  2043.  *  Support routines for dealing with gadgets.
  2044.  *
  2045.  *  Public Domain, but keep my name in it as the original author.
  2046.  *  31-Aug-88    Jan Sven Trabandt   first release version
  2047.  *  30-Sep-88    Jan Sven Trabandt   split from gadget.c (and improved)
  2048.  *                    renamed clearGadget to clearGadgets
  2049.  *  31-Oct-88    Jan Sven Trabandt   removed addGadgets, removeGadgets
  2050.  *                      since system AddGList, RemoveGList exists
  2051.  *                    changed order of clearGadgets parms to
  2052.  *                      match RefreshGadgets more closely
  2053.  *                    moved toggleBoolGadget from gadget.c
  2054.  */
  2055.  
  2056.  
  2057. #define I_AM_GADGSTUFF
  2058. #include "gimmelib/gimmefuncs.h"
  2059.  
  2060.  
  2061. short clearGadgets( gp, window, req, numgad )
  2062.     struct Gadget    *gp;
  2063.     struct Window    *window;
  2064.     struct Requester    *req;
  2065.     SHORT        numgad;
  2066. {
  2067.     register struct Image   *ip;
  2068.     struct RastPort        *rp;
  2069.     APTR            temp;
  2070.     register SHORT        pick, onoff;    /* use as front/back as well */
  2071.     SHORT            left, top;
  2072.     SHORT            propborder;
  2073.     struct Image        image;
  2074.     struct IntuiText        itext;
  2075.     BYTE            backpen;
  2076.  
  2077. #ifdef GIMME_WIMPY
  2078.     if( !window ) {
  2079.     return( -1 );
  2080.     }
  2081. #endif
  2082.     rp = window->RPort;
  2083.     if( gp && !(gp->GadgetType & REQGADGET) ) {
  2084.     req = NULL;
  2085.     }
  2086.     if( req ) {
  2087.     backpen = req->BackFill;
  2088.     if( req->ReqLayer && req->ReqLayer->rp ) {
  2089.         rp = req->ReqLayer->rp;
  2090.     }
  2091.     } else if( (backpen = window->RPort->BgPen) == -1 ) {
  2092.     backpen = 0;
  2093.     }
  2094.     for( ; gp && numgad != 0; gp = gp->NextGadget, --numgad ) {
  2095.     left = gp->LeftEdge;
  2096.     if( gp->Flags & GRELRIGHT ) {
  2097.         left += (req ? req->Width : window->Width) - 1;
  2098.     }
  2099.     top = gp->TopEdge;
  2100.     if( gp->Flags & GRELBOTTOM ) {
  2101.         top += (req ? req->Height : window->Height) - 1;
  2102.     }
  2103.     propborder = 0;
  2104.     if( (gp->GadgetType & ~GADGETTYPE) == PROPGADGET ) {
  2105.         if( !(((struct PropInfo *)gp->SpecialInfo)->Flags
  2106.                         & PROPBORDERLESS) ) {
  2107.         propborder = 1;
  2108.         }
  2109.     }
  2110.     if( (gp->Flags & SELECTED) && (gp->Flags & GADGHIMAGE)
  2111.         && gp->SelectRender ) {
  2112.         (APTR) ip = gp->SelectRender;
  2113.     } else {
  2114.         (APTR) ip = gp->GadgetRender;
  2115.     }
  2116.     if( gp->Flags & GADGIMAGE ) {
  2117.         while( ip ) {
  2118.         if( propborder ) {
  2119.             ip->LeftEdge += 4;
  2120.             ip->TopEdge += 2;
  2121.         }
  2122.         pick = ip->PlanePick;
  2123.         onoff = ip->PlaneOnOff;
  2124.         ip->PlanePick = 0x0;
  2125.         ip->PlaneOnOff = backpen;
  2126.         temp = (APTR) ip->NextImage;
  2127.         ip->NextImage = NULL;
  2128.         DrawImage( rp, ip, (long) left, (long) top );
  2129.         ip->NextImage = (struct Image *) temp;
  2130.         ip->PlanePick = pick;
  2131.         ip->PlaneOnOff = onoff;
  2132.         if( propborder ) {
  2133.             ip->LeftEdge -= 4;
  2134.             ip->TopEdge -= 2;
  2135.         }
  2136.         ip = (struct Image *) temp;
  2137.         } /* while */
  2138.     } else {            /* else it's a border */
  2139.         while( (struct Border *) ip ) {
  2140.         if( propborder ) {
  2141.             ((struct Border *)ip)->LeftEdge += 4;
  2142.             ((struct Border *)ip)->TopEdge += 2;
  2143.         }
  2144.         pick = ((struct Border *)ip)->FrontPen;
  2145.         onoff = ((struct Border *)ip)->BackPen;
  2146.         ((struct Border *)ip)->FrontPen = backpen;
  2147.         ((struct Border *)ip)->BackPen = backpen;
  2148.         temp = (APTR) ((struct Border *)ip)->NextBorder;
  2149.         ((struct Border *)ip)->NextBorder = NULL;
  2150.         DrawBorder( rp, (struct Border *) ip, (long) left, (long) top );
  2151.         ((struct Border *)ip)->NextBorder = (struct Border *) temp;
  2152.         ((struct Border *)ip)->FrontPen = pick;
  2153.         ((struct Border *)ip)->BackPen = onoff;
  2154.         if( propborder ) {
  2155.             ((struct Border *)ip)->LeftEdge -= 4;
  2156.             ((struct Border *)ip)->TopEdge -= 2;
  2157.         }
  2158.         (struct Border *)ip = (struct Border *) temp;
  2159.         } /* while */
  2160.     }
  2161.     (struct IntuiText *) ip = gp->GadgetText;
  2162.     while( (struct IntuiText *) ip ) {
  2163.         pick = ((struct IntuiText *)ip)->FrontPen;
  2164.         onoff = ((struct IntuiText *)ip)->BackPen;
  2165.         ((struct IntuiText *)ip)->FrontPen = backpen;
  2166.         ((struct IntuiText *)ip)->BackPen = backpen;
  2167.         temp = (APTR) ((struct IntuiText *)ip)->NextText;
  2168.         ((struct IntuiText *)ip)->NextText = NULL;
  2169.         PrintIText( rp, (struct IntuiText *) ip, (long) left, (long) top );
  2170.         ((struct IntuiText *)ip)->NextText = (struct IntuiText *) temp;
  2171.         ((struct IntuiText *)ip)->FrontPen = pick;
  2172.         ((struct IntuiText *)ip)->BackPen = onoff;
  2173.         (struct IntuiText *)ip = (struct IntuiText *) temp;
  2174.     } /* while */
  2175.         /* the actual strgadget string is rendered in the screen's font
  2176.          * but initially using Screen->BarLayer->rp->Font
  2177.          */
  2178. /*****
  2179.     if( (gp->GadgetType & ~GADGETTYPE) == STRGADGET ) {
  2180.         sip = (struct StringInfo *) gp->SpecialInfo;
  2181.         itext.BackPen = itext.FrontPen = backpen;
  2182.         itext.DrawMode = JAM2;
  2183.         itext.TopEdge = itext.LeftEdge = 0;
  2184.         itext.ITextFont = window->WScreen->Font;
  2185.         itext.IText = &sip->Buffer[sip->DispPos];
  2186.         tempchar = itext.IText[sip->DispCount];
  2187.         itext.IText[sip->DispCount] = '\0';
  2188.         itext.NextText = NULL;
  2189.         PrintIText( rp, &itext, (long) sip->CLeft, (long) sip->CTop );
  2190.         itext.IText[sip->DispCount] = tempchar;
  2191.     }
  2192. *****/
  2193.     if( (gp->GadgetType & ~GADGETTYPE) == PROPGADGET
  2194.         || (gp->GadgetType & ~GADGETTYPE) == STRGADGET ) {
  2195.         image.LeftEdge = 0;
  2196.         image.TopEdge = 0;
  2197.         image.Width = gp->Width;
  2198.         if( gp->Flags & GRELWIDTH ) {
  2199.         image.Width += req ? req->Width : window->Width;
  2200.         }
  2201.         image.Height = gp->Height;
  2202.         if( gp->Flags & GRELHEIGHT ) {
  2203.         image.Height += req ? req->Height : window->Height;
  2204.         }
  2205.         image.Depth = 0;
  2206.         image.ImageData = NULL;
  2207.         image.PlanePick = 0;
  2208.         image.PlaneOnOff = backpen;
  2209.         image.NextImage = NULL;
  2210.         DrawImage( rp, &image, (long) left, (long) top );
  2211.     }
  2212.     } /* for */
  2213.     return( 0 );
  2214. } /* clearGadgets */
  2215.  
  2216.  
  2217. short toggleBoolGadget( window, gp, req )
  2218.     struct Window        *window;
  2219.     register struct Gadget  *gp;
  2220.     struct Requester        *req;
  2221. {
  2222.     APTR        temp;
  2223.     USHORT        pos;
  2224.     SHORT        pick, onoff;
  2225.  
  2226. #ifdef GIMME_WIMPY
  2227.     if( !window || !gp ) {
  2228.     return( -1 );
  2229.     }
  2230. #endif
  2231.     if( (gp->GadgetType & ~GADGETTYPE) != BOOLGADGET ) {
  2232.     return( 0 );
  2233.     }
  2234.     if( (pos = RemoveGadget(window, gp)) == (USHORT) -1 ) {
  2235.     return( -1 );
  2236.     }
  2237.     gp->NextGadget = NULL;
  2238.     if( gp->Flags & GADGIMAGE ) {
  2239.     clearGadgets( gp, window, req, 1 );
  2240.     temp = gp->GadgetRender;
  2241.     gp->GadgetRender = gp->SelectRender;
  2242.     gp->SelectRender = temp;
  2243.     gp->Width = ((struct Image *)gp->GadgetRender)->Width;
  2244.     gp->Height = ((struct Image *)gp->GadgetRender)->Height;
  2245.     } else {
  2246.     temp = (APTR) gp->GadgetText;
  2247.     gp->GadgetText = (struct IntuiText *) gp->SelectRender;
  2248.     gp->SelectRender = temp;
  2249.     }
  2250.     gp->Flags &= ~SELECTED;
  2251.     AddGList( window, gp, (long) pos, 1L, req );
  2252.     RefreshGList( gp, window, req, 1L );
  2253.     return( 0 );
  2254. } /* toggleBoolGadget */
  2255.  
  2256.  
  2257. struct Gadget *findGadget( gp, id )
  2258.     register struct Gadget  *gp;
  2259.     USHORT  id;
  2260. {
  2261.     for( ; gp; gp = gp->NextGadget ) {
  2262.     if( gp->GadgetID == id ) {
  2263.         break;
  2264.     }
  2265.     } /* for */
  2266.     return( gp );
  2267. } /* findGadget */
  2268.  
  2269.  
  2270. struct Gadget *findMyFirstGadget( gp, id )
  2271.     register struct Gadget  *gp;
  2272.     USHORT  id;
  2273. {
  2274.     for( ; gp; gp = gp->NextGadget ) {
  2275.     if( gp->GadgetID > id ) {
  2276.         break;
  2277.     }
  2278.     } /* for */
  2279.     return( gp );
  2280. } /* findMyFirstGadget */
  2281. SHAR_EOF
  2282. #    End of shell archive
  2283. exit 0
  2284. -- 
  2285. Bob Page, U of Lowell CS Dept.  page@swan.ulowell.edu  ulowell!page
  2286. Have five nice days.
  2287.